package edu.szu.huhanpeng.doodlingFight.controller.mainHandler 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.model.data.GameData;
	import edu.szu.huhanpeng.doodlingFight.model.GameProxy;
	import edu.szu.huhanpeng.doodlingFight.model.ScoreProxy;
	import org.puremvc.as3.interfaces.IAsyncCommand;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.AsyncMacroCommand;
	import org.puremvc.as3.patterns.command.MacroCommand;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class HrGameOver extends SimpleCommand implements ICommand, INotifier 
	{
		private static const MSG_A:String = "游戏结束\n";
		private static const MSG_B:String = "  获得胜利！！！\n";
		private static const MSG_C:String = "的得分为： ";
		private static const MSG_D:String = "点击确定重新开始";
		private static const NR:String = "\n";
		
		override public function execute(note:INotification):void 
		{
			var gameProxy:GameProxy = facade.retrieveProxy( GameProxy.NAME ) as GameProxy;
			var scoreProxy:ScoreProxy =  facade.retrieveProxy( ScoreProxy.NAME ) as ScoreProxy;
			
			var loserCodeName:int = GameData.getTheOtherPlayer(scoreProxy.owner);
			
			var winerName:String = gameProxy.getPlayerName( scoreProxy.owner );
			var loserName:String = gameProxy.getPlayerName( loserCodeName );
			var winerScore:int = scoreProxy.score;
			var loserScore:int = gameProxy.getPlayerScore( loserCodeName ).score;
			
			var msg:String = MSG_A + winerName + MSG_B + winerName + MSG_C + winerScore.toString() + NR + loserName + MSG_C + loserScore.toString();
			
			sendNotification( GlobalConst.noteName.SHOW_MSG_DLG, [msg,restart] );
		}
		
		private function restart():void
		{
			sendNotification( GlobalConst.noteName.RESTRAR_GAME );
		}
	}

}